package org.lucky_common.util;

import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Tag(name = "响应Ajax数据")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AjaxResult {

    @Schema(description = "返回响应码的")
    private Integer code;
    @Schema(description = "返回的数据")
    private Object data;
    @Schema(description = "状态")
    private Boolean success;
    @Schema(description = "操作提示信息")
    private String msg;

    public static AjaxResult success(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(true);
        ajaxResult.setMsg(ResponseCode.RESPONSE_CODE_200.getMessage());
        ajaxResult.setCode(ResponseCode.RESPONSE_CODE_200.getCode());
        return ajaxResult;
    }
    public static AjaxResult successMsg(String msg){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(true);
        ajaxResult.setMsg(msg);
        ajaxResult.setCode(ResponseCode.RESPONSE_CODE_200.getCode());
        return ajaxResult;
    }
    public static AjaxResult success(Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(true);
        ajaxResult.setMsg(ResponseCode.RESPONSE_CODE_200.getMessage());
        ajaxResult.setCode(ResponseCode.RESPONSE_CODE_200.getCode());
        ajaxResult.setData(data);
        return ajaxResult;
    }
    public static AjaxResult error(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg("失败");
        return ajaxResult;
    }
    public static AjaxResult error(String msg){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }
    public static AjaxResult error(String msg,Integer code){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg(msg);
        ajaxResult.setCode(code);
        return ajaxResult;
    }
}